﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paring22_vastus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Paring22Vastus))]
    public class Paring22VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParing22Vastus clazz;
        
        public Paring22VastusSerializer(IParing22Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            for (int x = 0; ((clazz.Item != null) 
                        && (x < clazz.Item.Count)); x = (x + 1)) {
                if (clazz.Item[x]!=null) {
                    Writer.WriteStartElement("item");
                    global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData(clazz.Item[x]);
                    Writer.WriteTypeAttribute(metaItem.TypeQualifiedName.Namespace, metaItem.TypeQualifiedName.Name);
                    metaItem.NewSerializer(clazz.Item[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="item") {
                clazz.Item = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IParing22Soidukiandmed>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "item")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paring22_vastus>item");
                    }
                    global::Xtee.Core.SerializationMetadata metaItem = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IParing22Soidukiandmed>(Reader, "paring22_soidukiandmed", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                    global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IParing22Soidukiandmed item = metaItem.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IParing22Soidukiandmed>();
                    clazz.Item.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("item");
                        metaItem.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
